/**
 * Created by John on 2016/7/12.
 */
mongo.connect('mongodb://localhost/', function (err, db) {
    var myDB = db.db('words');
    myDB.collection("word_stats", function (err, collection) {
        collection.findOne(function (err, doc) {
            console.log(doc);
        })
    })
});

mongo = new MongoClient(new Server('localhosr', 27017));
mongo.open(function (err, mongoClient) {
    var db = mongoClient.db('myDB');
});

var MongoClient = require('mongodb').MongoClient;
var Server = require('mongodb').Server;
var mongo = new MongoClient();
mongo.connect('', function (err, db) {
    var myDB = db.db('words');
    myDB.collection('word_stats', function (err, collection) {
        //...
    })
});

var cursour = collection.find();
collection.find(function (err, cursor) {
    // ...
});

var options = {w: 1, j: true, wtimeout: 1000, fsync: true};

var ReadPreference = require('mongodb').ReadPreference;
options = {readPreference: ReadPreference.PRIMARY};

myColl.findOne(function (err, doc) {
    // ...
});

var cursor = myColl.find();
cursor.each(function (err, doc) {
    if (doc) {
        console.log(doc);
    }
});

curosr = myColl.find();
cursor.toArray(function (err, docs) {
    for (var i in docs) {
        console.log(docs[i]);
    }
});

var query = {size: 5};
cursor = myColl.find(query);

query = {size: {$gt: 5}};
curosr = myColl.find(query);

query = {first: {$in: ['x', 'y', 'z']}};
cursor.myColl.find(query);

cursor = wordsColl.find();
curosr.count(function (err, count) {
    console.log('count = ' + count);
})

var sorter = {name: 1};
cursor = mycollection.find();
cursor.sort(sorter, function (err, items) {

});

sorter = [{name: 1}, {value: -1}];
cursor = mycollection.find();
cursor.sort(sorter, function (items) {
    // ...
});

var sorter1={name:1};
var sorter2={value:-1};
cursor=mycollection.find();
cursor=curosr.sort(sorter1);
curosr.sort(sorter2,function (err, items) {
    // ...
});